package com.fr.report.write;

import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.data.DBManipulation;
import com.fr.data.core.db.dml.Table;
import com.fr.report.Report;
import com.fr.report.TableDataSource;
import com.fr.report.core.FormException;
import com.fr.report.core.FormReport;
import com.fr.report.script.Calculator;
import com.fr.report.script.ParameterMapNameSpace;
import com.fr.report.write.config.ColumnConfig;
import com.fr.report.write.config.DMLConfig;
import com.fr.report.write.config.IntelliDMLConfig;
import java.util.Map;

public class BuiltInSQLSubmiter extends AbstractSubmiter
{
  private DBManipulation dbManipulation;

  public DBManipulation getDBManipulation()
  {
    return this.dbManipulation;
  }

  public void setDBManipulation(DBManipulation paramDBManipulation)
  {
    this.dbManipulation = paramDBManipulation;
  }

  public String getDBName()
  {
    return ((this.dbManipulation == null) ? null : this.dbManipulation.getDBName());
  }

  public void setDBName(String paramString)
  {
    if (this.dbManipulation == null)
      this.dbManipulation = new DBManipulation();
    this.dbManipulation.setDBName(paramString);
  }

  public DMLConfig getDmlConfig()
  {
    return ((this.dbManipulation == null) ? null : this.dbManipulation.getDmlConfig());
  }

  public void setDmlConfig(DMLConfig paramDMLConfig)
  {
    if (this.dbManipulation == null)
      this.dbManipulation = new DBManipulation();
    this.dbManipulation.setDmlConfig(paramDMLConfig);
  }

  public void execute(Report paramReport, TableDataSource paramTableDataSource, Map paramMap)
    throws Exception
  {
    try
    {
      super.execute(paramReport, paramTableDataSource, paramMap);
    }
    catch (MismatchException localMismatchException)
    {
      return;
    }
    if (!(paramReport instanceof FormReport))
      throw new FormException("Application can only submit the data of form report.");
    Calculator localCalculator = Calculator.createCalculator();
    localCalculator.setCurrentReport(paramReport);
    localCalculator.setCurrentTableDataSource(paramTableDataSource);
    localCalculator.pushNameSpace(ParameterMapNameSpace.create(paramMap));
    this.dbManipulation.commit2db(localCalculator);
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isAttr())
      this.dbManipulation = new DBManipulation();
    this.dbManipulation.readXML(paramXMLableReader);
  }

  /**
   * @deprecated
   */
  public void readOldXML(XMLableReader paramXMLableReader)
  {
    paramXMLableReader.readXMLObject(new XMLReadable(this)
    {
      private final BuiltInSQLSubmiter this$0;

      public void readXML()
      {
        String str;
        Object localObject1;
        if (paramXMLableReader.isAttr())
        {
          if ((str = paramXMLableReader.getAttr("dsName")) != null)
            this.this$0.setDBName(str);
          localObject1 = new IntelliDMLConfig();
          this.this$0.setDmlConfig((DMLConfig)localObject1);
          if ((str = paramXMLableReader.getAttr("tableName")) != null)
            ((IntelliDMLConfig)localObject1).setTable(new Table(str));
        }
        if ((paramXMLableReader.isChildNode()) && ("Column".equals(paramXMLableReader.getTagName())))
        {
          localObject1 = null;
          boolean bool = false;
          if ((str = paramXMLableReader.getAttr("name")) != null)
            localObject1 = str;
          if ((str = paramXMLableReader.getAttr("isKey")) != null)
            bool = Boolean.valueOf(str).booleanValue();
          Object localObject2 = this.this$0.getDmlConfig();
          if (localObject2 == null)
          {
            localObject2 = new IntelliDMLConfig();
            this.this$0.setDmlConfig((DMLConfig)localObject2);
          }
          ((DMLConfig)localObject2).addColumnConfig(new ColumnConfig((String)localObject1, DBManipulation.readColumnValue(paramXMLableReader), bool, false));
        }
      }
    });
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    super.writeXML(paramXMLPrintWriter);
    if (this.dbManipulation != null)
      this.dbManipulation.writeXML(paramXMLPrintWriter);
  }

  public String toString()
  {
    return ((this.dbManipulation == null) ? "" : this.dbManipulation.toString());
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    BuiltInSQLSubmiter localBuiltInSQLSubmiter = (BuiltInSQLSubmiter)super.clone();
    if (this.dbManipulation != null)
      localBuiltInSQLSubmiter.dbManipulation = ((DBManipulation)this.dbManipulation.clone());
    return localBuiltInSQLSubmiter;
  }
}